
#ifndef SERVER_H 
#define SERVER_H 

#include <boost/asio/io_context.hpp>
#include <cstdint>
#include <iostream>
#include <boost/asio.hpp>
#include <memory>
#include <map>
#include <string>

#include "Session.h"

using boost::asio::ip::tcp;

class Server 
{
public:
    Server(boost::asio::io_context& ioc, uint16_t port)
    :_acceptor(ioc, tcp::endpoint(tcp::v4(), port))
    ,_ioc(ioc)
    {
        start_accept();
    }

    void delete_session(std::string id);

private:
    void start_accept();
    void handle_accept(const boost::system::error_code& error, std::shared_ptr<Session> session);

private:
    tcp::acceptor _acceptor;
    boost::asio::io_context& _ioc;
    //用于存储智能指针的链接，便于后续获取某个链接
    std::map<std::string, std::shared_ptr<Session>> _sessions; 
};

#endif	/* SERVER_H */
